#include "onlyread.hpp"

#include "qbe/src/ecs/app.hpp"
#include "qbe/src/axis/axis.hpp"
#include "qbe/src/input/input.hpp"
#include "qbe/src/select/select.hpp"
#include "qbe/src/state/state.hpp"

#include "qlib/all.h"

#include "../components.hpp"
#include "../events.hpp"

namespace qbe::draw::onlyread {
void exit(ecs::Query query, state::AllModeType enter_mode) {}

void init(entt::registry& reg, ecs::Commands commands, ecs::Query query) {}

void update(entt::registry& reg, ecs::Query query, ecs::Bus& bus, ecs::EventWriter<msg::RenderEvent> event) {
  auto& state = query.get_resource<state::State>();
  auto res = bus.receive<qbe::UiMessage::OnlyRead>();
  if (!res.empty()) {
  bool is_only_read = res[0].is_only_read;
  if(true == is_only_read)
  {
    state.switchMode(state::SelectModeType::None);
  }else{
    state.switchMode(state::SelectModeType::Overall); // 先默认为全选，后面记录之前的模式并恢复
  }
  }
  
}

void post(entt::registry& reg, ecs::Commands commands, ecs::Query query, ecs::Bus& bus) {}

}  // namespace qbe::draw::onlyread